using System;
using System.Collections.Generic;
using System.Text;
using Emlyn.Common.Data.DBUpdater;
using Emlyn.Common.Data.SqlServer.SqlManagers;

namespace Emlyn.Website.EmlynORegan.DBUpdateRules
{
    public class DUR_0070_CopyDataFromArticleListToArticleStructure: IDBUpdaterRule
    {
        #region IDBUpdaterRule Members

        public int UpgradeFromVersion()
        {
            return 60;
        }

        public int UpgradeToVersion()
        {
            return 70;
        }

        public void PerformUpgrade()
        {
            string lSql =
                "insert tblEOArticle " +
                "(ArticleID, ArticleCode, ArticleName, Url, ArticleContent, LastChanged) " +
                "select ArticleListID, ArticleListCode, ArticleListName, null, ArticleListDescription, GetUTCDate() " +
                "from tblEOArticleList ";
            SqlManager.Execute(lSql);

            lSql =
                "insert tblEOArticle_Article (Article_ArticleID, ParentArticleID, ChildArticleID) " +
                "select Article_ArticleListID, ArticleListID, ArticleID " +
                "from tblEOArticle_ArticleList ";
            SqlManager.Execute(lSql);

            lSql =
                "insert tblEOArticle_Article (Article_ArticleID, ParentArticleID, ChildArticleID) " +
                "select ArticleList_ArticleListID, ArticleListID, ChildArticleListID " +
                "from tblEOArticleList_ArticleList ";
            SqlManager.Execute(lSql);
        }

        #endregion
    }
}
